﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Snowdreamist.Collection
{
    public class ReadonlyConcurrentCollection<T> : IList<T>, ICollection<T>
    {
        public ReadonlyConcurrentCollection(ConcurrentCollection<T> collection)
        {
            if (collection == null)
                throw new ArgumentNullException("collection");
            this._collection = collection;
        }

        public void Add(T item)
        {
            throw new InvalidOperationException("Readonly collection");
        }

        public void Clear()
        {
            throw new InvalidOperationException("Readonly collection");
        }

        public bool Contains(T item)
        {
            return this._collection.Contains(item);
        }

        public void CopyTo(T[] array, int arrayIndex)
        {
            this._collection.CopyTo(array, arrayIndex);
        }

        public int Count
        {
            get
            {
                return this._collection.Count;
            }
        }

        public bool IsReadOnly
        {
            get
            {
                return true;
            }
        }

        public bool Remove(T item)
        {
            throw new InvalidOperationException("Readonly collection");
        }

        public IEnumerator<T> GetEnumerator()
        {
            return this._collection.GetEnumerator();
        }

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return this._collection.GetEnumerator();
        }

        public int IndexOf(T item)
        {
            return this._collection.IndexOf(item);
        }

        public void Insert(int index, T item)
        {
            throw new InvalidOperationException("Readonly collection");
        }

        public void RemoveAt(int index)
        {
            throw new InvalidOperationException("Readonly collection");
        }

        public T this[int index]
        {
            get
            {
                return this._collection[index];
            }
            set
            {
                throw new InvalidOperationException("Readonly collection");
            }
        }

        #region private

        private ConcurrentCollection<T> _collection;

        #endregion private
    }
}